package cc.yiueil.synchronous;

public class Deadlock {
    private void add() {
        synchronized (Count.LOCK1) {
            Count.value1 += 1;
            synchronized (Count.LOCK2) {
                Count.value2 += 1;
            }
        }
    }

    private void dec() {
        synchronized (Count.LOCK2) {
            Count.value2 -= 1;
            synchronized (Count.LOCK1) {
                Count.value1 -= 1;
            }
        }
    }
}

class Count {
    public static final Object LOCK1 = new Object();
    public static final Object LOCK2 = new Object();
    public static int value1 = 0;
    public static int value2 = 0;
}
